package com.sysu.homework.DAO.Impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.sysu.homework.DAO.HomeworkDAO;
import com.sysu.homework.model.Homework;
@Component("homeworkDAO")
public class HomeworkDAOImpl implements HomeworkDAO {
	private HibernateTemplate hibernateTemplate;

	@Override
	public int save(Homework homework) {
		if(homework.getId()>0)
			hibernateTemplate.update(homework);
		else
			hibernateTemplate.save(homework);
		
		return 1;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Override
	public List<Homework> getHomeworks() {
		return  hibernateTemplate.find("from Homework order by deadline");
	}

	@Override
	public Homework getHomeworkById(int id) {
		
		return (Homework)hibernateTemplate.get(Homework.class, id);
	}

	@Override
	public List<Homework> getUnrankHomeworks() {
		
		return null;
	}

	@Override
	public List<Homework> getUnGradeHomeworks() {
		return null;
	}

}
